#ifndef __dhs_util
#define __dhs_util

#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <string>

#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif

#ifdef __cplusplus
#define BEGIN_DECAL_C \
    extern "C"        \
    {
#else
#define BEGIN_DECAL_C
#endif

#ifdef __cplusplus
#define END_DECAL_C }
#else
#define END_DECAL_C
#endif

#ifdef DLL_BUILD
#define DHS_API __declspec(dllexport)
#else
#define DHS_API
#endif


#ifdef DEBUG

#define DHS_LOG(formater,args...) printf(formater,##args)
#else
#define DHS_LOG(formater,args...)  ((void)0)
#endif


static jmp_buf jmpBuf;

static void signal_fun(int sig){

// char buf[256];
// char * error= gets(buf);
  DHS_LOG("crash==============\n");
  longjmp(jmpBuf,1);
}


BEGIN_DECAL_C

#define BEGIN_EXCEPT    do{ \
signal(SIGSEGV,signal_fun); \
signal(SIGABRT,signal_fun); \
if(setjmp(jmpBuf)==1){ \
 break;}     \

#define END_EXCEPT     } while (0);

END_DECAL_C

std::string  getCurrentDir();
#endif

